#region File Description
//-----------------------------------------------------------------------------
// GameplayScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.IO;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input.Touch;
using Outliers;
using System.IO.IsolatedStorage;
#endregion

namespace OutliersSample
{
    /// <summary>
    /// This screen implements the actual game logic. It is just a
    /// placeholder to get the idea across: you'll probably want to
    /// put some more interesting gameplay in here!
    /// </summary>
    class GameplayScreen : GameScreen
    {
        #region Fields

        ContentManager content;
        SpriteFont gameFont;

        Vector2 playerPosition = new Vector2(100, 100);
        Vector2 enemyPosition = new Vector2(100, 100);

        Random random = new Random();
        
        float pauseAlpha;

       // public TouchCollection TouchState;

        InputAction pauseAction;

        // We store our input states so that we only poll once per frame, 
        // then we use the same input state wherever needed
        private GamePadState gamePadState;
        private KeyboardState keyboardState;
        private TouchCollection touchState;
        private AccelerometerState accelerometerState;

        #endregion

        #region jeremiah intialization

        // Resources for drawing.
        //private GraphicsDeviceManager graphics;
       // private SpriteBatch spriteBatch;

        // Jeremiah 3/11/2012
        // ScreenManager screenManager;

        // Global content.
        private SpriteFont hudFont; // hud = "heads up display"

        private Texture2D winOverlay;
        private Texture2D loseOverlay;
        private Texture2D diedOverlay;

        // Controls Overlays
        private Texture2D leftControl; // button to move player to the left
        private Texture2D rightControl; // button to move player to the right
        private Texture2D jumpControl; // button for jumping
        private Texture2D bulletControl; //button to shoot bullets
        

        // Meta-level game state.
        private int levelIndex = -1;
        private Level level;
       private bool wasContinuePressed;

        // When the time remaining is less than the warning time, it blinks on the hud
        private static readonly TimeSpan WarningTime = TimeSpan.FromSeconds(30);

        // We store our input states so that we only poll once per frame, 
        // then we use the same input state wherever needed
        //private GamePadState gamePadState;
        //private KeyboardState keyboardState;
        //private TouchCollection touchState;
        //private AccelerometerState accelerometerState;

        // The number of levels in the Levels directory of our content. We assume that
        // levels in our content are 0-based and that all numbers under this constant
        // have a level file present. This allows us to not need to check for the file
        // or handle exceptions, both of which can add unnecessary time to level loading.
        private const int numberOfLevels = 29; //12 means only 11 (talking 0-11)levels ;)

        #endregion 

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public GameplayScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);

            pauseAction = new InputAction(
                new Buttons[] { Buttons.Start, Buttons.Back },
                new Keys[] { Keys.Escape },
                true);


            //Jeremiah
            //JEREMIAH//graphics = new GraphicsDeviceManager(this);
            //graphics.PreferredBackBufferWidth = BackBufferWidth;
            // graphics.PreferredBackBufferHeight = BackBufferHeight;

           //JEREMIAH// Content.RootDirectory = "Content";

            // Create the screen manager component.
            //screenManager = new ScreenManager(this);

            // Components.Add(screenManager);

            // Activate the first screens.
            //screenManager.AddScreen(new BackgroundScreen(), null);
            //screenManager.AddScreen(new MainMenuScreen(), null);

            // Framerate differs between platforms.
            // TargetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / TargetFrameRate);






            //graphics = new GraphicsDeviceManager(this);
            //Content.RootDirectory = "Content";
            //JEREMIAH BELOW
//#if WINDOWS_PHONE
//            graphics.IsFullScreen = true;
//            TargetElapsedTime = TimeSpan.FromTicks(333333);
//#endif

//            Accelerometer.Initialize();

        }




        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (content == null)
                    content = new ContentManager(ScreenManager.Game.Services, "Content");

                gameFont = content.Load<SpriteFont>("gamefont");

                //JEREMIAH BELOW

                // Create a new SpriteBatch, which can be used to draw textures.
                SpriteBatch spriteBatch = ScreenManager.SpriteBatch; //new SpriteBatch(GraphicsDevice);//spriteBatch = new SpriteBatch(GraphicsDevice);

                // Load fonts
                hudFont = content.Load<SpriteFont>("Fonts/Hud");

                // Load overlay textures
                winOverlay = content.Load<Texture2D>("Overlays/you_win");
                loseOverlay = content.Load<Texture2D>("Overlays/you_lose");
                diedOverlay = content.Load<Texture2D>("Overlays/you_died");
                leftControl = content.Load<Texture2D>("Overlays/Left");
                rightControl = content.Load<Texture2D>("Overlays/Right");
                jumpControl = content.Load<Texture2D>("Overlays/Jump"); //jump overlay
                bulletControl = content.Load<Texture2D>("Overlays/Bullet"); //bullet overlay

                //Known issue that you get exceptions if you use Media PLayer while connected to your PC
                //See http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/c8a243d2-d360-46b1-96bd-62b1ef268c66
                //Which means its impossible to test this from VS.
                //So we have to catch the exception and throw it away
                //try
                //{
                //    MediaPlayer.IsRepeating = true;
                //    MediaPlayer.Play(Content.Load<Song>("Sounds/Music"));
                //}
                //catch { }

                //LoadLevelMusic();
                LoadNextLevel();

                // A real game would probably have more content than this sample, so
                // it would take longer to load. We simulate that by delaying for a
                // while, giving you a chance to admire the beautiful loading screen.
                //Thread.Sleep(1000);

                // once the load has finished, we use ResetElapsedTime to tell the game's
                // timing mechanism that we have just finished a very long frame, and that
                // it should not try to catch up.
               // ScreenManager.Game.ResetElapsedTime();
            }

#if WINDOWS_PHONE
            if (Microsoft.Phone.Shell.PhoneApplicationService.Current.State.ContainsKey("PlayerPosition"))
            {
                playerPosition = (Vector2)Microsoft.Phone.Shell.PhoneApplicationService.Current.State["PlayerPosition"];
                enemyPosition = (Vector2)Microsoft.Phone.Shell.PhoneApplicationService.Current.State["EnemyPosition"];
            }
#endif
        }


        public override void Deactivate()
        {
#if WINDOWS_PHONE
            Microsoft.Phone.Shell.PhoneApplicationService.Current.State["PlayerPosition"] = playerPosition;
            Microsoft.Phone.Shell.PhoneApplicationService.Current.State["EnemyPosition"] = enemyPosition;
#endif

            base.Deactivate();
        }


        /// <summary>
        /// Unload graphics content used by the game.
        /// </summary>
        public override void Unload()
        {
            content.Unload();

#if WINDOWS_PHONE
            Microsoft.Phone.Shell.PhoneApplicationService.Current.State.Remove("PlayerPosition");
            Microsoft.Phone.Shell.PhoneApplicationService.Current.State.Remove("EnemyPosition");
#endif
        }


        #endregion


        #region jeremiah outliers game methods



        //LoadNextLevel Method - Loads the next level in the hopper (array)
        private void LoadNextLevel()
        {
            // move to the next level
            levelIndex = (levelIndex + 1) % numberOfLevels;

            // Loads the next levels music :D - works grrrrreat :D
            LoadLevelMusic();

            // Unloads the content for the current level before loading the next one.
            if (level != null)
                level.Dispose();

            // Load the level.
            string levelPath = string.Format("Content/Levels/{0}.txt", levelIndex);
            using (Stream fileStream = TitleContainer.OpenStream(levelPath))
                level = new Level(ScreenManager.Game.Services, fileStream, levelIndex);

            ////////// Find the path of the next level.
            ////////string levelPath;

            ////////// Loop here so we can try again when we can't find a level.
            ////////while (true)
            ////////{
            ////////    // Try to find the next level. They are sequentially numbered txt files.
            ////////    levelPath = String.Format("Levels/{0}.txt", ++levelIndex);
            ////////    levelPath = Path.Combine(StorageContainer.TitleLocation, "Content/" + levelPath);
            ////////    if (File.Exists(levelPath))
            ////////        break;

            ////////    // If there isn't even a level 0, something has gone wrong.
            ////////    if (levelIndex == 0)
            ////////        throw new Exception("No levels found.");

            ////////    // Whenever we can't find a level, start over again at 0.
            ////////    // TODO: Put a finish screen with scores here
            ////////    levelIndex = -1;
            ////////    break;
            ////////}

            ////////if (levelIndex == -1)
            ////////{
            ////////    //We've finished, test score for high score and show mainmenu again

            ////////    ScreenManager.AddScreen(new FinishedScreen(), ControllingPlayer);

            ////////    TestHighScore();

            ////////}
            ////////else
            ////////{
            ////////    // Unloads the content for the current level before loading the next one.
            ////////    if (level != null)
            ////////    {
            ////////        //totalScore = level.Score;
            ////////        level.Dispose();
            ////////    }

            ////////    // Load the level.
            ////////    level = new Level(ScreenManager.Game.Services, levelPath, totalScore, levelIndex, currentLives);
            ////////}
        }

        //LoadLevelMusic Method - Loads the music for each level
        private void LoadLevelMusic()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;

            switch (levelIndex)
            {
                case 0: // scene 1
                    {
                        try
                        {

                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                    MediaPlayer.IsRepeating = true;
                                    //11-14-2012 MediaPlayer.Stop();
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene1Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene1Outliers"));
                            }

                           // MediaPlayer.IsRepeating = true; //Groton wakes from coma
                           // MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene1Outliers"));
                        }
                        catch { }
                        break;
                    }
                case 1:
                    {
                        try
                        {

                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                    //musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true;
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ExpandYourPotential"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true;
                                MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ExpandYourPotential"));
                            }

                          //  MediaPlayer.IsRepeating = true;
                           // MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ExpandYourPotential"));
                        }
                        catch { }
                        break;
                    }
                case 2:
                    {
                        try
                        {
                            //MediaPlayer.IsRepeating = true;
                           // MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ExpandYourPotential"));
                            //MediaPlayer.Play(Content.Load<Song>("Sounds/Scenes/OutliersSCENE2Reunion"));
                        }
                        catch { }
                        break;
                    }
                case 3: //scene 2
                    {
                        try
                        {

                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                   // musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene2Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene2Outliers"));
                            }
                            //MediaPlayer.IsRepeating = true; //Groton wakes from coma
                            //MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene2Outliers"));
                        }
                        catch { }
                        break;
                    }
                case 4: //level4.txt
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                  //  musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true;
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/JungleTheme"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true;
                                MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/JungleTheme"));
                            }


                           // MediaPlayer.IsRepeating = true;
                            //MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/JungleTheme"));
                            //MediaPlayer.Play(Content.Load<Song>("Sounds/Scenes/OutliersSCENE3HelloOldFriend"));
                        }
                        catch { }
                        break;
                    }
                case 5: //level5.txt
                    {
                        try
                        {
                            //MediaPlayer.IsRepeating = true; //login into the tor network
                           // MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/OutliersSCENE2Reunion"));

                           // MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/JungleTheme"));
                        }
                        catch { }
                        break;
                    }
                case 6: // Scene 3
                    {
                        try
                        {

                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                 //   musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene3Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene3Outliers"));
                            }
                           // MediaPlayer.IsRepeating = true; //Groton wakes from coma
                            //MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene3Outliers"));
                        }
                        catch { }
                        break;
                    }
                case 7: //level7.txt
                    {
                        try
                        {

                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                    //musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true;
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ForThoseAboutToRock"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true;
                                MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ForThoseAboutToRock"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 8: //level8.txt
                    {
                        try
                        {
                            //MediaPlayer.IsRepeating = true;
                            //MediaPlayer.Play(Content.Load<Song>("Sounds/Soundtrack/JungleTheme"));
                        }
                        catch { }
                        break;
                    }
                case 9: // Scene 4
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                    //musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene4Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene4Outliers"));
                            }


                        }
                        catch { }
                        break;
                    }
                case 10: //level10.txt
                    {
                        try
                        {

                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                 //   musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton saves Zander
                                    //MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/OutliersSCENE3HelloOldFriend"));
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/TranceDanceInTheMiddleGround"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton saves Zander
                                //MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/OutliersSCENE3HelloOldFriend"));
                                MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/TranceDanceInTheMiddleGround"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 11: //level11.txt
                    {
                        try
                        {
                            //MediaPlayer.IsRepeating = true;
                            //MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ForThoseAboutToRock"));
                        }
                        catch { }
                        break;
                    }
                case 12: // Scene 5
                    {
                        try
                        {

                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                    //musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene5Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene5Outliers"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 13: //  
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                    //musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true;
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ForThoseAboutToRock"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true;
                                MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ForThoseAboutToRock"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 14: //  
                    {
                        try
                        {
                           // MediaPlayer.IsRepeating = true;
                           // MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ForThoseAboutToRock"));
                        }
                        catch { }
                        break;
                    }
                case 15: //  Scene 6
                    {
                        try
                        {

                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                  //  musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene6Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene6Outliers"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 16: //  
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                    //musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true;
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/CanWeDoThatAgain"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true;
                                MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/CanWeDoThatAgain"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 17: //  
                    {
                        try
                        {
                         //   MediaPlayer.IsRepeating = true;
                        //    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ForThoseAboutToRock"));
                        }
                        catch { }
                        break;
                    }
                case 18: //  Scene 7
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                    //musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene7Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene7Outliers"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 19: //  
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                   // musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true;
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/CanWeDoThatAgain"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true;
                                MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/CanWeDoThatAgain"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 20: //  
                    {
                        try
                        {
                         //   MediaPlayer.IsRepeating = true;
                        //    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ForThoseAboutToRock"));
                        }
                        catch { }
                        break;
                    }
                case 21: //  Scene 8 - Ian
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                   // musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene8Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene8Outliers"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 22: //  
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                    //musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true;
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/SoThisIsWhatHeavenIsLike"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true;
                                MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/SoThisIsWhatHeavenIsLike"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 23: //  
                    {
                        try
                        {
                          //  MediaPlayer.IsRepeating = true;
                         //   MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ForThoseAboutToRock"));
                        }
                        catch { }
                        break;
                    }
                case 24: //  Scene 9 - Meeting Zander 1st time since Jungle
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                   // musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene9Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene9Outliers"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 25: //  Journey to Japan
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                   // musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true;
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ExpandYourPotential"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true;
                                MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ExpandYourPotential"));
                            }

                        }
                        catch { }
                        break;
                    }
                case 26: //  Jouney to Japan
                    {
                        try
                        {
                         //   MediaPlayer.IsRepeating = true;
                        //    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/ForThoseAboutToRock"));
                        }
                        catch { }
                        break;
                    }
                case 27: // Scene 10 -  Zander - Hazure-Chi Facility
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                   // musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene10Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene10Outliers"));
                            }
                           // MediaPlayer.IsRepeating = true; //Groton wakes from coma
                            //MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene10Outliers"));
                        }
                        catch { }
                        break;
                    }
                case 28: //  Scene 11 - Success!
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                   // musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene11Outliers"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true; //Groton wakes from coma
                                MediaPlayer.Play(content.Load<Song>("Sounds/Scenes/Scene11Outliers"));
                            }

                        }
                        catch { }
                        break;
                    }
                default:
                    {
                        try
                        {
                            if (settings.Contains("MusicSetting"))
                            {

                                //Retrieve data stored in the settings
                                string determineMusicSettingAfterRelaunch = settings["MusicSetting"].ToString();

                                if (determineMusicSettingAfterRelaunch == "false")
                                {
                                   // musicCanPlay = false;
                                }
                                else
                                {
                                    MediaPlayer.IsRepeating = true;
                                    MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/SoThisIsWhatHeavenIsLike"));
                                }
                            }
                            else //if the isolated storage setting hasn't been created yet, then create it and set it to "off" to turn off music.
                            {
                                //should only hit this the first time the app is run
                                MediaPlayer.IsRepeating = true;
                                MediaPlayer.Play(content.Load<Song>("Sounds/Soundtrack/SoThisIsWhatHeavenIsLike"));
                            }

                        }
                        catch { }
                        break;
                    }
            }

        }


        private void ReloadCurrentLevel()
        {
            --levelIndex;
            LoadNextLevel();
        }


        #endregion

        #region Update and Draw


        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {

            // Get the raw touch state from the TouchPanel
            touchState = TouchPanel.GetState();
           
            base.Update(gameTime, otherScreenHasFocus, false);

            // Gradually fade in or out depending on whether we are covered by the pause screen.
            if (coveredByOtherScreen)
                pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1);
            else
                pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0);

           // if (IsActive)
            //{
                // Apply some random jitter to make the enemy move around.
                //const float randomization = 10;

               // enemyPosition.X += (float)(random.NextDouble() - 0.5) * randomization;
               // enemyPosition.Y += (float)(random.NextDouble() - 0.5) * randomization;

                // Apply a stabilizing force to stop the enemy moving off the screen.
               // Vector2 targetPosition = new Vector2(
                  //  ScreenManager.GraphicsDevice.Viewport.Width / 2 - gameFont.MeasureString("Insert Gameplay Here").X / 2, 
                  //  200);

              //  enemyPosition = Vector2.Lerp(enemyPosition, targetPosition, 0.05f);

                // TODO: this game isn't very fun! You could probably improve
                // it by inserting something more interesting in this space :-)

                // Handle polling for our input and handling high-level input
               // HandleInput();

                // update our level, passing down the GameTime along with all of our input states
                //level.Update(gameTime, keyboardState, gamePadState, touchState,
                  //           accelerometerState, Window.CurrentOrientation);

                if (IsActive)
                {
                    //HandleInput();

                    //level.Update(gameTime);

                    level.Update(gameTime, keyboardState, gamePadState, touchState, accelerometerState);//, Window.CurrentOrientation);

                    base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
                }

                base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

               //JEREMIAH I MAY BE OK WITHOUT THIS FOR NOW BECAUSE IT'S ABOVE MAYBE NOT THOUGH!! base.Update(gameTime);
           // }
        }


        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            // Get the raw touch state from the TouchPanel
            TouchCollection TouchState = TouchPanel.GetState();

           // touchState = TouchPanel.GetState();

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[playerIndex];

            PlayerIndex player;
            if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected)
            {
#if WINDOWS_PHONE
                ScreenManager.AddScreen(new PhonePauseScreen(), ControllingPlayer);
#else
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
#endif
            }
            else
            {
                // Otherwise move the player position.
                Vector2 movement = Vector2.Zero;

                if (keyboardState.IsKeyDown(Keys.Left))
                    movement.X--;

                if (keyboardState.IsKeyDown(Keys.Right))
                    movement.X++;

                if (keyboardState.IsKeyDown(Keys.Up))
                    movement.Y--;

                if (keyboardState.IsKeyDown(Keys.Down))
                    movement.Y++;

                Vector2 thumbstick = gamePadState.ThumbSticks.Left;

                movement.X += thumbstick.X;
                movement.Y -= thumbstick.Y;

                if (input.TouchState.Count > 0)
                {
                    Vector2 touchPosition = input.TouchState[0].Position;
                    Vector2 direction = touchPosition - playerPosition;
                    direction.Normalize();
                    movement += direction;
                    //level.Update(gameTime, TouchState);
                }

                if (movement.Length() > 1)
                    movement.Normalize();

                playerPosition += movement * 8f;


                //level.Update(gameTime, TouchState);

                bool continuePressed =
                keyboardState.IsKeyDown(Keys.Space) ||
                gamePadState.IsButtonDown(Buttons.A) ||
                touchState.AnyTouch();

                // Perform the appropriate action to advance the game and
                // to get the player back to playing.
                if (!wasContinuePressed && continuePressed)
                {
                    if (!level.Player.IsAlive)
                    {
                        level.StartNewLife();
                    }
                    else if (level.TimeRemaining == TimeSpan.Zero)
                    {
                        if (level.ReachedExit)
                            LoadNextLevel();
                        else
                            ReloadCurrentLevel();
                    }
                }

                wasContinuePressed = continuePressed;


            }
        }


        //f'd
        ///////////////////// <summary>
        ///////////////////// Draws the game from background to foreground.
        ///////////////////// </summary>
        ///////////////////// <param name="gameTime">Provides a snapshot of timing values.</param>
        //////////////////protected override void Draw(GameTime gameTime)
        //////////////////{


        //////////////////    ////////////////////////////////graphics.GraphicsDevice.Clear(Color.Black);

        //////////////////    ////////////////////////////////// The real drawing happens inside the screen manager component.
        //////////////////    ////////////////////////////////base.Draw(gameTime);

        //////////////////    //////////////////////////graphics.GraphicsDevice.Clear(Color.CornflowerBlue);


        //////////////////    ////////////////////////////  spriteBatch.Begin();

        //////////////////    //////////////////////////level.Draw(gameTime, spriteBatch);

        //////////////////    //////////////////////////DrawHud();

        //////////////////    ////////////////////////////  spriteBatch.End();

        //////////////////    //////////////////////////base.Draw(gameTime);

        //////////////////    ////////////// This game has a blue background. Why? Because!
        //////////////////    ////////////ScreenManager.GraphicsDevice.Clear(ClearOptions.Target,
        //////////////////    ////////////                                   Color.CornflowerBlue, 0, 0);

        //////////////////    ////////////// Our player and enemy are both actually just text strings.
        //////////////////    ////////////SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

        //////////////////    //////////////graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

        //////////////////    //////////////spriteBatch.Begin();

        //////////////////    ////////////level.Draw(gameTime, spriteBatch);

        //////////////////    ////////////DrawHud();

        //////////////////    //////////////spriteBatch.End();

        //////////////////    ////////////base.Draw(gameTime);
        //////////////////}

        /// <summary>
        /// Draws the gameplay screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            // This game has a blue background. Why? Because!
            ScreenManager.GraphicsDevice.Clear(ClearOptions.Target,
                                               Color.CornflowerBlue, 0, 0);

            // Our player and enemy are both actually just text strings.
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            //graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            //spriteBatch.Begin();

            level.Draw(gameTime, spriteBatch);

            DrawHud();

            //spriteBatch.End();

            base.Draw(gameTime);

            // If the game is transitioning on or off, fade it out to black.
            if (TransitionPosition > 0)
                ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha);
        }

        //Drawing the  "Heads Up Display" HUD
        private void DrawHud()
        {
            //spriteBatch.Begin(); //2012

            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            spriteBatch.Begin();
            Rectangle titleSafeArea = ScreenManager.GraphicsDevice.Viewport.TitleSafeArea;

            //Rectangle titleSafeArea = GraphicsDevice.Viewport.TitleSafeArea;
            Vector2 hudLocation = new Vector2(titleSafeArea.X, titleSafeArea.Y);
            Vector2 center = new Vector2(titleSafeArea.X + titleSafeArea.Width / 2.0f,titleSafeArea.Y + titleSafeArea.Height / 2.0f);

            // Draw time remaining. Uses modulo division to cause blinking when the
            // player is running out of time.
            string timeString = "TIME REMAINING: " + level.TimeRemaining.Minutes.ToString("00") + ":" + level.TimeRemaining.Seconds.ToString("00");
            Color timeColor;
            if (level.TimeRemaining > WarningTime ||
                level.ReachedExit ||
                (int)level.TimeRemaining.TotalSeconds % 2 == 0)
            {
                timeColor = Color.White;
            }
            else
            {
                timeColor = Color.Red;
            }
            DrawShadowedString(hudFont, timeString, hudLocation, timeColor);

            // Draw score
            float timeHeight = hudFont.MeasureString(timeString).Y;
            DrawShadowedString(hudFont, "SCORE: " + level.Score.ToString(), hudLocation + new Vector2(0.0f, timeHeight * 1.2f), Color.White);

            // Left Controller image drawing
            //800x480 (Windows Phone 7)
            Vector2 leftControlSize = new Vector2(1, 380); //x,y
            spriteBatch.Draw(leftControl, leftControlSize, Color.White);

            // Right Controller image drawing
            //800x480 (Windows Phone 7)
            Vector2 rightControlSize = new Vector2(130, 380); //x,y
            spriteBatch.Draw(rightControl, rightControlSize, Color.White);

            // Bullet Controller image drawing
            //800x480 (Windows Phone 7)
            Vector2 bulletControlSize = new Vector2(550, 380); //x,y
            spriteBatch.Draw(bulletControl, bulletControlSize, Color.White);

            // Jump Controller image drawing
            //800x480 (Windows Phone 7)
            Vector2 jumpControlSize = new Vector2(660, 380); //x,y
            spriteBatch.Draw(jumpControl, jumpControlSize, Color.White);


            

            // Determine the status overlay message to show.
            Texture2D status = null;
            if (level.TimeRemaining == TimeSpan.Zero)
            {
                if (level.ReachedExit)
                {
                    status = winOverlay;
                }
                else
                {
                    status = loseOverlay;
                }
            }
            else if (!level.Player.IsAlive)
            {
                status = diedOverlay;
            }

            if (status != null)
            {
                // Draw status message.
                Vector2 statusSize = new Vector2(status.Width, status.Height);
                spriteBatch.Draw(status, center - statusSize / 2, Color.White);
            }

            

            spriteBatch.End(); //2012
        }

        //DrawShadowedString - For Strings in the game
        private void DrawShadowedString(SpriteFont font, string value, Vector2 position, Color color)
        {


            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            spriteBatch.DrawString(font, value, position + new Vector2(1.0f, 1.0f), Color.Black);
            spriteBatch.DrawString(font, value, position, color);
            //spriteBatch.DrawString(font, value, position + new Vector2(1.0f, 1.0f), Color.Black);
            //spriteBatch.DrawString(font, value, position, color);
        }

        ///// <summary>
        ///// Draws the gameplay screen.
        ///// </summary>
        //public override void Draw(GameTime gameTime)
        //{
        //    // This game has a blue background. Why? Because!
        //    ScreenManager.GraphicsDevice.Clear(ClearOptions.Target,
        //                                       Color.CornflowerBlue, 0, 0);

        //    // Our player and enemy are both actually just text strings.
        //    SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

        //    //graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

        //    //spriteBatch.Begin();

        //    level.Draw(gameTime, spriteBatch);

        //    DrawHud();

        //    //spriteBatch.End();

        //    base.Draw(gameTime);

        //    // If the game is transitioning on or off, fade it out to black.
        //    if (TransitionPosition > 0)
        //        ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha);
        //}

        ///////// <summary>
        ///////// THEIRS Draws the gameplay screen.
        ///////// </summary>
        //////public override void Draw(GameTime gameTime)
        //////{
        //////    // This game has a blue background. Why? Because!
        //////    ScreenManager.GraphicsDevice.Clear(ClearOptions.Target,
        //////                                       Color.CornflowerBlue, 0, 0);

        //////    // Our player and enemy are both actually just text strings.
        //////    SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

        //////    spriteBatch.Begin();

        //////    spriteBatch.DrawString(gameFont, "// TODO", playerPosition, Color.Green);

        //////    spriteBatch.DrawString(gameFont, "Insert Gameplay Here",
        //////                           enemyPosition, Color.DarkRed);

        //////    spriteBatch.End();

        //////    // If the game is transitioning on or off, fade it out to black.
        //////    if (TransitionPosition > 0 || pauseAlpha > 0)
        //////    {
        //////        float alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, pauseAlpha / 2);

        //////        ScreenManager.FadeBackBufferToBlack(alpha);
        //////    }
        //////}


        #endregion
    }
}
